package com.test.reggie.model.address;

import com.test.reggie.base.BaseObserver;
import com.test.reggie.base.BasePresenter;
import com.test.reggie.bean.AddAddressBean;
import com.test.reggie.bean.AddressBookListBean;
import com.test.reggie.bean.StringBean;

import java.util.Map;

public class AddressPrensenter extends BasePresenter<AddressView> {
    public AddressPrensenter(AddressView baseView) {
        super(baseView);
    }

    /**
     * 查询指定用户的全部地址
     *
     * @param userId
     */
    public void addressBookList(String userId) {
        addDisposable(apiServer.addressBookList(userId), new BaseObserver<AddressBookListBean>() {
            @Override
            public void onSuccess(AddressBookListBean bean) {
                baseView.addressBookListSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 设置默认地址
     *
     * @param map
     */
    public void setDefault(Map<String, Object> map) {
        addDisposable(apiServer.setDefault(map), new BaseObserver<AddAddressBean>() {
            @Override
            public void onSuccess(AddAddressBean bean) {
                baseView.setDefaultSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 删除地址
     *
     * @param ids
     */
    public void deleteAddressBook(String ids) {
        addDisposable(apiServer.deleteAddressBook(ids), new BaseObserver<StringBean>() {
            @Override
            public void onSuccess(StringBean bean) {
                baseView.deleteAddressBookSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }
}
